<?php
class IndexAction extends Action{
	function index(){
		if(empty($_REQUEST['show'])){
			$showid='';
		}else{
			$showid=$_REQUEST['show'];
		}
		//$this->display('Query:'.'index'.$showid.'.html');
		$this->display('index'.$showid);
	}
	function infolist(){
	$info=new InfoViewModel();
	
	$map = array();	
	
	if(!empty($_REQUEST['jyfanshi'])){$map['jyfanshi'] = $_REQUEST["jyfanshi"];}//经营方式
	if(!empty($_REQUEST['typeid'])){
		
		$map['typeid'] = $_REQUEST['typeid'];//许可证件
	}else{
		$info=M('Info');
	}
	if(!empty($_REQUEST['fanwei'])){$map['fanwei'] = $_REQUEST['fanwei'];}//经营范围
	if(!empty($_REQUEST['zdfenlei1'])){$map['zdfenlei1'] = $_REQUEST['zdfenlei1'];}//重点监管食品分类
	if(!empty($_REQUEST['zdfenlei2'])){$map['zdfenlei2'] = $_REQUEST['zdfenlei2'];}//是否清真
	if(!empty($_REQUEST['zdfenlei3'])){$map['zdfenlei1'] = $_REQUEST['zdfenlei3'];}//重点监管食品子类
	if(!empty($_REQUEST['xuexiao'])){$map['xuexiao'] = $_REQUEST['xuexiao'];}//学校及校园周边
	if(!empty($_REQUEST['liudongche'])){$map['liudongche'] = $_REQUEST['liudongche'];}//流动配货车辆情况
	if(!empty($_REQUEST['xinyong'])){$map['xinyong'] = $_REQUEST['xinyong'];}//信用登记
	if(!empty($_REQUEST['anquanshifan'])){$map['anquanshifan'] = $_REQUEST['anquanshifan'];}//食品安全示范店
	if(!empty($_REQUEST['leixing'])){//企业类型
		$aid=$_REQUEST['leixing'];
		if($aid == 20){
		$map['leixing'] = array(array('egt',20),array('lt',30),'and') ;		
		}elseif($aid == 30){
		$map['leixing'] = array(array('egt',30),array('lt',40),'and') ;		
		}
		else{
		$map['leixing'] = $_REQUEST['leixing'];	
		}
	}
	if(!empty($_REQUEST['guanxia'])){$map['guanxia'] = $_REQUEST['guanxia'];}//管辖工商所
	if(!empty($_REQUEST['xchzu'])){$map['xchzu'] = $_REQUEST['xchzu'];}//巡查队
	if($_REQUEST['jgrenyuan']!="监管人员姓名" and !empty($_REQUEST['jgrenyuan'])){$map['jgrenyuan'] = $_REQUEST['jgrenyuan'];}//监管人员姓名
	if($_REQUEST['zhuangan']!="食品监管专干姓名" and !empty($_REQUEST['zhuangan'])){$map['zhuangan'] = $_REQUEST['zhuangan'];}//食品监管专干
	if($_REQUEST['xinxiyuan']!="食品安全信息员姓名" and !empty($_REQUEST['xinxiyuan'])){$map['xinxiyuan'] = $_REQUEST['xinxiyuan'];}//食品安全信息员
	if($_REQUEST['lianluoyuan']!="食品安全联络员姓名" and !empty($_REQUEST['lianluoyuan'])){$map['lianluoyuan'] = $_REQUEST['lianluoyuan'];}//食品安全联络员
	if($_REQUEST['xieguanyuan']!="食品安全协管员姓名" and !empty($_REQUEST['xieguanyuan'])){$map['xieguanyuan'] = $_REQUEST['xieguanyuan'];}//食品安全协管员
	//echo $_REQUEST['jyfanshi'];
	import("ORG.Util.Page");// 导入分页类	
	$count = $info->Distinct(true)->where($map)->count();// 查询满足要求的总记录数
	
	if (! empty ( $_REQUEST ['p'] )) {
				$listRows = $_REQUEST ['p'];
			} else {
				$listRows = '';
	}
			
	$p = new Page ( $count,10 );
	
	//分页查询数据
	$voList = $info->Distinct(true)->where($map)->order("id")->limit($p->firstRow . ',' . $p->listRows)->select();
	//分页跳转的时候保证查询条件
	foreach ( $map as $key => $val ) {
				if (! is_array ( $val )) {
					$p->parameter .= "$key=" . urlencode ( $val ) . "&";
				}else {    
         foreach($val as $t) { //为数组的时候继续分条件。主要就是这里了 加上这里就可以了          
         	$p->parameter .= $key."=".urlencode(str_replace("%","",$t))."&";
         }
      }
				
	}
	$show       = $p->show();// 分页显示输出
	$sql=$info->getlastsql();
	$this->assign('sql',$sql);
	$this->assign('list',$voList);
	$this->assign('page',$show);// 赋值分页输出	
	$this->display();
	}
	
	function infoshow(){
		//echo"hh";

	$info=D('Xuke');
	$list=$info->relation(true)->select();	
	dump($list);
	}
}
?>